/*
 * 展示销售渠道信息交易
 * 参数   交易码：trancode=15120
 * 
 */

package org.ccams.tran;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.ccams.domain.TSalesChannel;
import org.ccams.util.PageParameter;

public class Tran15120 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		int limit = Integer.parseInt(request.getParameter("limit"));
		int start = Integer.parseInt(request.getParameter("start"));
		PageParameter page = new PageParameter();
		page.setLimit(limit);
		page.setStart(start);
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		ArrayList<TSalesChannel> al = new ArrayList<TSalesChannel>();
		List<TSalesChannel> list = getCcamsService().getTsaleschannelDao().getTSalesChannel(page);
		int count = getCcamsService().getTsaleschannelDao().getCount();
		if(list.size()>0){
			for(TSalesChannel t : list){
				TSalesChannel u = new TSalesChannel();
				u.setDescription(t.getDescription());
				u.setLoanInvOrg1(t.getLoanInvOrg1());
				u.setLoanInvOrg2(t.getLoanInvOrg2());
				u.setLoanSubinventory1(t.getLoanSubinventory1());
				u.setLoanSubinventory2(t.getLoanSubinventory2());
				u.setMeaning(t.getMeaning());
				u.setSalesChannelCode(t.getSalesChannelCode());
				u.setSalesZoneId(t.getSalesZoneId());
				u.setZoneName(t.getZoneName());
				al.add(u);
			}
		}
		JSONArray JsonArray = JSONArray.fromObject(al); //得到JSON数组 
		jsonMap.put("totalProperty", count);
        jsonMap.put("root", JsonArray);
        json.putAll(jsonMap);
	}
}
